package org.googlecode.lightning.search.index;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;

/**
 * the field
 * 
 * @author daragon
 * 
 */
public enum IndexField implements IIndexField {

	ID("id", Store.YES, Index.NOT_ANALYZED),

	FILE_NAME("filename", Store.YES, Index.NO),

	CONTENT("content", Store.YES, Index.ANALYZED),

	LAST_MODIFIED("lastModified", Store.YES, Index.NO),

	FILE_EXT("extension", Store.NO, Index.NOT_ANALYZED);

	private String indexFieldName;
	private Store store;
	private Index index;

	/**
	 * 
	 * @param indexName
	 * @param store
	 * @param index
	 */
	private IndexField(String indexName, Store store, Index index) {
		this.indexFieldName = indexName;
		this.store = store;
		this.index = index;
	}


	public String getIndexName() {
		return indexFieldName;
	}

	public Store getStore() {
		return store;
	}

	public Index getIndex() {
		return index;
	}

	public Field toField(String value) {
		// for highlighter ,you can add TermVector,this will be more quick than normal type.
		// new Field(indexFieldName, value, store, index, Field.TermVector.WITH_POSITIONS_OFFSETS)
		return new Field(indexFieldName, value, store, index);
	}


	public void addToDoc(Document doc, String value) {
		doc.add(toField(value));
	}


	public void removeFromDoc(Document doc) {
		doc.removeField(indexFieldName);
	}

	public String getFromDoc(Document doc) {
		return doc.get(indexFieldName);
	}
}
